package com.kly.sc.api.application.controller.appEvaluate;

import com.fqgj.common.api.Response;
import com.kly.sc.api.application.controller.appEvaluate.response.EvaluateRes;
import com.kly.sc.api.application.service.utils.RedisService;
import com.kly.sc.api.application.utils.Result;
import com.kly.user.constant.RedisKey;
import com.kly.user.service.UserEvaluateRewardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/evaluate")
@Api(value = "/api/evaluate", tags = "商店评价")
public class AppEvaluateController {

    @Resource
    private UserEvaluateRewardService userEvaluateRewardService;

    @Autowired
    RedisService redisService;


    @GetMapping("/check")
    @ApiOperation(value = "是否需要弹窗奖励", notes = "是否需要弹窗奖励")
    public Result<EvaluateRes> check(@RequestParam @ApiParam("userCode") String userCode) {
        EvaluateRes evaluateRes = new EvaluateRes();
        evaluateRes.setStatus(0);
        Response<Integer> evaluateRewardResponse = userEvaluateRewardService.evaluateReward(userCode);
        if (evaluateRewardResponse.isSuccess()) {
            evaluateRes.setStatus(evaluateRewardResponse.getData());
            Long number = redisService.getNumber(RedisKey.FLASH_CHAT_COUNT);
            evaluateRes.setMessage(String.valueOf(number));
        }
        return Result.ok(evaluateRes);
    }

    @GetMapping("/goEvaluate")
    @ApiOperation(value = "去应用商店评价", notes = "去应用商店评价")
    public Result goEvaluate(@RequestParam @ApiParam("userCode") String userCode) {
        userEvaluateRewardService.addReward(userCode);
        return Result.ok();
    }

    @GetMapping("/backApp")
    @ApiOperation(value = "评价后返回app", notes = "评价后返回app")
    public Result backApp(@RequestParam @ApiParam("userCode") String userCode) {
        userEvaluateRewardService.sendMessage(userCode);
        return Result.ok();
    }
}
